package tables

import (
	"github.com/GoAdminGroup/go-admin/context"
	"github.com/GoAdminGroup/go-admin/modules/db"
	"github.com/GoAdminGroup/go-admin/plugins/admin/modules/table"
	"github.com/GoAdminGroup/go-admin/template/types"
	"github.com/GoAdminGroup/go-admin/template/types/form"
)

func GetResourcesTable(ctx *context.Context) table.Table {
	tableName := "storage_resources"
	title := "Resources"

	resources := table.NewDefaultTable(table.DefaultConfigWithDriver("mysql"))


	thisInfo := resources.GetInfo()

	thisInfo.SetFilterFormLayout(form.LayoutThreeCol)

	thisInfo.AddField("Id", "id", db.Int).FieldFilterable().FieldSortable()
	thisInfo.AddField("App_id", "app_id", db.Int).FieldFilterable().FieldSortable()
	thisInfo.AddField("Account_id", "account_id", db.Int).FieldFilterable().FieldSortable()
	thisInfo.AddField("Parent_id", "parent_id", db.Int).FieldHide().FieldFilterable().FieldSortable()
	thisInfo.AddField("Refer_count", "refer_count", db.Int).FieldFilterable().FieldSortable()
	thisInfo.AddField("Title", "title", db.Varchar).FieldFilterable().FieldSortable()
	thisInfo.AddField("Path", "path", db.Varchar).FieldHide().FieldFilterable().FieldSortable()
	thisInfo.AddField("Extension", "extension", db.Varchar).FieldFilterable().FieldSortable()
	thisInfo.AddField("Mime", "mime", db.Varchar).FieldHide().FieldFilterable().FieldSortable()
	thisInfo.AddField("Md5", "md5", db.Varchar).FieldHide().FieldFilterable().FieldSortable()
	thisInfo.AddField("Sha1", "sha1", db.Varchar).FieldHide().FieldFilterable().FieldSortable()
	thisInfo.AddField("Size", "size", db.Varchar).FieldFilterable().FieldSortable()
	thisInfo.AddField("Description", "description", db.Text).FieldHide().FieldFilterable().FieldSortable()
	thisInfo.AddField("Created_by", "created_by", db.Int).FieldFilterable().FieldSortable()
	thisInfo.AddField("Sort", "sort", db.Tinyint).FieldFilterable().FieldSortable()
	thisInfo.AddField("Created_at", "created_at", db.Timestamp).FieldFilterable(types.FilterType{FormType: form.DatetimeRange}).FieldSortable()
	thisInfo.AddField("Updated_at", "updated_at", db.Timestamp).FieldFilterable(types.FilterType{FormType: form.DatetimeRange}).FieldSortable()
	thisInfo.AddField("Deleted_at", "deleted_at", db.Timestamp).FieldFilterable(types.FilterType{FormType: form.DatetimeRange}).FieldSortable()

	thisInfo.SetTable(tableName).SetTitle(title).SetDescription("List")


	thisForm := resources.GetForm()

	thisForm.AddField("Id", "id", db.Int, form.Default).
		FieldDisableWhenCreate()
	thisForm.AddField("App_id", "app_id", db.Int, form.Number).
		FieldDefault("0")
	thisForm.AddField("Account_id", "account_id", db.Int, form.Number)
	thisForm.AddField("Parent_id", "parent_id", db.Int, form.Number)
	thisForm.AddField("Refer_count", "refer_count", db.Int, form.Number)
	thisForm.AddField("Title", "title", db.Varchar, form.Text)
	thisForm.AddField("Path", "path", db.Varchar, form.Text)
	thisForm.AddField("Extension", "extension", db.Varchar, form.Text)
	thisForm.AddField("Mime", "mime", db.Varchar, form.Text)
	thisForm.AddField("Md5", "md5", db.Varchar, form.Text).
		FieldHide()
	thisForm.AddField("Sha1", "sha1", db.Varchar, form.Text).
		FieldHide()
	thisForm.AddField("Size", "size", db.Varchar, form.Text).
		FieldHide()
	thisForm.AddField("Description", "description", db.Text, form.RichText)
	thisForm.AddField("Created_by", "created_by", db.Int, form.Number)
	thisForm.AddField("Sort", "sort", db.Tinyint, form.Number)
	thisForm.AddField("Created_at", "created_at", db.Timestamp, form.Datetime).
		FieldHide().FieldNowWhenInsert()
	thisForm.AddField("Updated_at", "updated_at", db.Timestamp, form.Datetime).
		FieldHide().FieldNowWhenUpdate()
	thisForm.AddField("Deleted_at", "deleted_at", db.Timestamp, form.Datetime)

	thisForm.SetTable(tableName).SetTitle(title).SetDescription("Edit")


	detail := resources.GetDetailFromInfo()

	detail.SetTable(tableName).SetTitle(title).SetDescription("List")


	return resources
}
